home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.02 Jun 92 / Simple Antivirus Protection / VirusCheck.p < prev    next >
Encoding:
Text File  |  1992-05-20  |  3.4 KB  |  124 lines  |  [TEXT/MPS ]

  1. {Written by Nicholas Pisarro, Jr., Aperture Technologies, Inc.
  2.  No rights reserved.}
  3.  
  4. UNIT VirusCheck;
  5.  
  6. INTERFACE
  7.  
  8. USES
  9.     {$LOAD}
  10.         MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf;
  11.     
  12.  
  13. {Returns TRUE if Application can run.}
  14. FUNCTION ApplicationCanRun: BOOLEAN;
  15.  
  16.  
  17. IMPLEMENTATION
  18.  
  19. {Returns TRUE if Application can run.}
  20. FUNCTION ApplicationCanRun: BOOLEAN;
  21.     CONST
  22.         kVirusChkKinds        =    '????';    {Rsrc type for the # 'CODE' & # of Kinds of resources}
  23.         kVirusChkID            =    32;        {Resource ID for the Virus Check Rsrc}
  24.         
  25.         {The Virus found alert and its sub-messages}
  26.         kVirusAlrt            =    1282;        {A Virus has been detected!}
  27.         kCountRsrcMissing    =    1;            {The Resource count Resource is missing}
  28.         kTypeMiscount        =    2;            {Wrong number of resource types}
  29.         kRsrcMiscount        =    3;            {Wrong number of a specific res. kind}
  30.         
  31.     TYPE
  32.         {Resource & Count list.}
  33.         RsrcCount = RECORD
  34.             RType:        ResType;
  35.             RCount:        INTEGER;
  36.         END;
  37.         
  38.         RsrcRSRC = ARRAY[0..32000] OF RsrcCount;
  39.         pRsrcRSRC = ^RsrcRSRC;
  40.         hRsrcRSRC = ^pRsrcRSRC;
  41.         
  42.     VAR
  43.         {For counting Resources.}
  44.         theResType:        ResType;            { The kind we’re looking for }
  45.         subMsgNo:        INTEGER;            { Submessage number }
  46.         msgStr,                                { Submessage to go into dialog}
  47.         workStr:            Str255;            { Resource name to go into the message }
  48.         
  49.         aRsrcRSRC:        hRsrcRSRC;        { Handle to the Count Rsrc}
  50.         
  51.         i:                    INTEGER;
  52.         dummy:            INTEGER;
  53.     
  54.     LABEL 100;
  55. BEGIN        { ApplicationCanRun }
  56.     ApplicationCanRun := FALSE;            {Assume failure.}
  57.     
  58.     {Virus Check: Load resources with counts of various kinds of resources
  59.      in Application. Make sure the counts in the resource match the actual
  60.      counts in Application.}
  61.     workStr[0] := CHR(0);                {Make WorkStr have no length.}
  62.     
  63.     {Try to get the counts of the various resources in the Application.}
  64.     aRsrcRSRC := hRsrcRSRC(Get1Resource(kVirusChkKinds, kVirusChkID));
  65.     IF aRsrcRSRC <> NIL THEN BEGIN
  66.         
  67.         {Check out each of the counts read.}
  68.         FOR i := 0 TO GetHandleSize(Handle(aRsrcRSRC)) div SIZEOF(RsrcCount) - 1 DO BEGIN
  69.             
  70.             {If the kind is a 0, a total resource count is wanted.}
  71.             IF ORD(aRsrcRSRC^^[i].RType[1]) = 0 THEN BEGIN
  72.                 
  73.                 {Does the total number of resource kinds in the Application
  74.                  match the count the resource?}
  75.                 IF (Count1Types <> aRsrcRSRC^^[i].RCount) THEN BEGIN
  76.                     
  77.                     subMsgNo := kTypeMiscount;        { Sub message }
  78.                     
  79.                     {Issue a Virus Alert to the user.}
  80. 100:                GetIndString(msgStr, kVirusAlrt, subMsgNo);
  81.                     ParamText(msgStr, workStr, '', '');
  82.                     dummy := StopAlert(kVirusAlrt, NIL);
  83.                     
  84.                     EXIT(ApplicationCanRun);
  85.                 END;
  86.             END
  87.             
  88.             {Otherwise, check a specific type.}
  89.             ELSE BEGIN
  90.                 
  91.                 {Does the number of this kind of resource in the Application
  92.                  match the count the resource?}
  93.                 theResType := aRsrcRSRC^^[i].RType;
  94.                 IF Count1Resources(theResType) <> aRsrcRSRC^^[i].RCount THEN BEGIN
  95.                     
  96.                     { Make a string out of the resource type. }
  97.                     WorkStr[0] := CHR(4);
  98.                     BlockMove(@theResType[1], @workStr[1], 4);
  99.                     
  100.                     subMsgNo := kRsrcMiscount;        { Sub message }
  101.                     
  102.                     GOTO 100;
  103.                 END;
  104.             END;
  105.         END;        {End FOR i…}
  106.         
  107.         {Finished with the resource}
  108.         ReleaseResource(Handle(aRsrcRSRC));
  109.     END            {End IF aRsrcRSRC <> NIL}
  110.     
  111.     {Count Resource not found.}
  112.     ELSE BEGIN
  113.         subMsgNo := kCountRsrcMissing;            { Sub message }
  114.         
  115.         GOTO 100;
  116.     END;
  117.     
  118.     {Possibly put other virus checks, checks for the proper system version,
  119.      etc. here.}
  120.     
  121.     ApplicationCanRun := TRUE;            {Success!}
  122. END;        { ApplicationCanRun }
  123.  
  124. END.